package com.hulizuofang.wol.chat.server;

import java.io.Serializable;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.hulizuofang.wol.chat.client.data.ChatUser;

@PersistenceCapable
public class ChatUserJDO implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String id;
	
	@Persistent
	private String login;

	@Persistent
	private boolean active;
	
	protected ChatUserJDO() {/* GWT only constructor */}
	
	public ChatUserJDO(String id, String login, boolean active) {
		this.id = id;
		this.login = login;
		this.active = active;
	}
	
	public ChatUserJDO(ChatUser chatUser) {
		this(chatUser.getId(), chatUser.getLogin(), chatUser.isActive());
	}
	
	public ChatUserJDO(String login) {
		this(null,login,true);
	}
	public String getId() {
		return id;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	
	@Override
	public String toString() {
		return "(id: "+id+", login: "+login+", active: "+active+")";
	}
	
	public ChatUser asChatUser() {
		return new ChatUser(id, login, active);
	}
}